package org.qpcr.community.device.web;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.authorization.annotation.*;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.qpcr.community.device.entity.DeviceModuleStateEntity;
import org.qpcr.community.device.service.DeviceModuleStateService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;




@RestController
@RequestMapping("/device/moduleState")
@Authorize
@Resource(id="device-moduleState",name = "设备状态上报")
@Slf4j
@Tag(name = "设备状态上报管理")
@RequiredArgsConstructor
public class DeviceModuleStateController implements ReactiveServiceCrudController<DeviceModuleStateEntity, String>{

    @Getter
    private final DeviceModuleStateService service;

    @PostMapping("/no-auth")
    @SaveAction
    @Operation(
        summary = "新增"
    )
    @Authorize(ignore = true)
    public  Mono<Void> addOverride(@RequestBody DeviceModuleStateEntity  payload) {
        log.debug("设备状态上报管理-新增：设备id:"+payload.getDeviceId()+":"+payload.toString());
        return service.saveData(payload);
    }

    @GetMapping({"/_query/{deviceId}"})
    @QueryAction
    @Operation(summary = "查询设备的模块列表")
    public Flux<DeviceModuleStateEntity> query(@PathVariable @Parameter(description = "设备ID") String deviceId) {
        return service.getList(deviceId);
    }

    @DeleteMapping({"/{deviceId}/{id}"})
    @DeleteAction
    @Operation(
        summary = "根据设备id和模块ID删除"
    )
    public Mono<Void> delete(@PathVariable String deviceId,@PathVariable String id) {
        return service.delete(deviceId,id);
    }

}
